<?php
defined("_ALLOW") or die ("Access denied");
?>
<?php
if (isset($_REQUEST['email']) && isset($_REQUEST['password'])) {
	$email = $_REQUEST['email'];
	$password = $_REQUEST['password'];
	global $csdl;
	$strsql = "SELECT * FROM `mk_users` WHERE `email`='$email' AND `password`=md5('$password') AND active=1";
	$rows = $csdl->Truyvan($strsql);
	if ($csdl->sodong==0)
		mosRedirect("index.php?loginfail=1");
	else {
		$row = mysql_fetch_array($rows,MYSQL_ASSOC);
		if ($row['active']==0) {
//			echo "T&agrave;i kho&#7843;n ch&#432;a k&iacute;ch ho&#7841;t";
			mosRedirect("index.php?loginfail=1");
		}
		else {
			$_SESSION['username'] = $email;
			$_SESSION['hoten'] = $row['hoten'];
//			echo "&#272;&#259;ng nh&#7853;p th&agrave;nh c&ocirc;ng. V&#7873; <a href='index.php'>trang ch&#7911;</a>";
		}
	}
}
?>
<?php
if (!isset($_SESSION['username']) || $_SESSION['username']=="") {
?>
<script language="javascript">
function checkfrmlogin () {
	var frm = document.frmlogin;
	var email = frm.email.value;
	var password = frm.password.value;
	email = trim(email);
	password = trim(password);
	frm.email.value = email;
	frm.password.value = password;
	if (email == "" || password == "") {
		alert("Vui lòng cung cấp email và password");
	}
	else
		frm.submit();
}
</script>
<form action="index.php" method="post" name="frmlogin">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
             
              <tr>
                <td valign="top" >
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
							<td style="background-image:url(images/dangnhap1.jpg); background-repeat:no-repeat;" height="35" class="col_left">
							Hội viên đăng nhập		
							</td>
						</tr>
                    <tr>
                      <td height="20" valign="bottom" class="register">Email :</td>
                    </tr>
                    <tr>
                      <td valign="bottom" style="padding-left:10px;"><input name="email" type="text" id="email" size="25" style="width:180px;" /></td>
                    </tr>
                    <tr>
                      <td height="20" valign="bottom" class="register">Mật khẩu :</td>
                    </tr>
                    <tr>
                      <td valign="bottom" style="padding-left:10px;"><input name="password" type="password" id="password" size="25" style="width:180px;" /></td>
                    </tr>
                    <tr>
                      <td height="20" valign="bottom" class="mod_user" ><a href="javascript:checkfrmlogin(document.frmlogin)" >Đăng nhập</a> | <a href="index.php?module=com_usergetpassword" >Quên mật khẩu</a></td>
                    </tr>
                    <tr>
                      <td height="20" valign="bottom" class="mod_user" ><?php if (isset($_GET['loginfail'])) echo "<span style='font-weight:normal;font-style:italic;'>Sai email/password<br /></span>"; ?><a href="index.php?module=com_userregister" >Đăng ký</a></td>
                    </tr>

                </table></td>
              </tr>
            </table></form>
<?php
}
else {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
							<td style="background-image:url(images/dangnhap1.jpg); background-repeat:no-repeat;" height="35" class="col_left">
							Thông tin cá nhân		
							</td>
						</tr>
              <tr>
                <td valign="top">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="style3" style="padding-left:10px; padding-top:10px; font-family:Tahoma; font-size:12px; color:#990000; font-weight:bold;">
			<?php echo $_SESSION['hoten']; ?>
					  </td>
                    </tr>
                    <tr>
                      <td height="25" valign="bottom" style="padding-left:10px;" class="canhan"><a href="index.php?module=com_userregister" >Thông tin cá nhân</a></td>
                    </tr>
					<tr><td height="25" valign="bottom" style="padding-left:10px;" class="canhan">
					<a href="index.php?module=com_userlistproduct" >Quản trị sản phẩm</a>
					</td></tr>
                    <tr>
                      <td height="25" valign="bottom" style="padding-left:10px;" class="canhan"><a href="index.php?module=com_useraddproduct">Đăng sản phẩm</a></td>
                    </tr>
                    <tr>
                      <td class="canhan" style="padding-left:10px; padding-top:10px;"><a href="index.php?module=com_userlogout" >Logout</a></td>
                    </tr>

                </table></td>
              </tr>
            </table>
<?php
}
?>